package xaj.puiatti;

import java.io.Reader;
import java.util.Collection;
import java.util.List;

import polyglot.ast.NodeFactory;
import polyglot.frontend.CupParser;
import polyglot.frontend.FileSource;
import polyglot.frontend.Job;
import polyglot.frontend.OutputPass;
import polyglot.frontend.Parser;
import polyglot.frontend.Pass;
import polyglot.lex.Lexer;
import polyglot.types.TypeSystem;
import polyglot.util.ErrorQueue;
import polyglot.visit.Translator;
import xaj.puiatti.ast.PuiattiNodeFactory_c;
import xaj.puiatti.parse.Grm;
import xaj.puiatti.parse.Lexer_c;
import xaj.scc.types.SCTypeSystem_c;

public class ExtensionInfo extends abc.aspectj.ExtensionInfo {
		
	public ExtensionInfo(Collection<String> jar_classes, Collection<String> aspect_sources) {
		super(jar_classes, aspect_sources);
	}

	static {
        // force Topics to load
        new Topics();
    }
	
	//Nome do compilador do syntaxclass
	public String compilerName() {
		return "puiatti";
	}
	
	//Retorna o parser do syntaxclass
	public Parser parser(Reader reader, FileSource source, ErrorQueue eq) {
        Lexer lexer = new Lexer_c(reader, source.path(), eq);
        Grm grm = new Grm(lexer, ts, nf, eq);
        return new CupParser(grm, source, eq);
    }
	
	//Retorna o fabrica de nó do syntaxclass
    protected NodeFactory createNodeFactory() {
        return new PuiattiNodeFactory_c();
    }

    //Retorna o sistema de tipos do syntaxclass
    protected TypeSystem createTypeSystem() {
        return new SCTypeSystem_c();
    }
	
    public List<Pass> passes(Job job) {
    	List<Pass> passes =	super.passes(job);
    	//Passe que imprime o código gerado na pasta output
    	passes.add(new OutputPass(Pass.OUTPUT, job,
                new Translator(job, ts, nf, targetFactory())));
    	return passes;
    }
    
    protected Options createOptions() {
    	return new Options(this);
    }
    
    public String[] defaultFileExtensions() {
        String [] extnames = {"aj", "java", "sc"};
        return extnames;
     }

}
